JavaScript Value Properties

Visualizing `globalThis`, `Infinity`, `NaN`, and `undefined`.

globalThis

A standard way to access the global object, regardless of the environment (browser or Node.js). It's a universal reference to the top-level scope.

// In a browser:
console.log(globalThis === window); // true

// In Node.js:
console.log(globalThis === global); // true

Think of globalThis as a central hub, connecting to different environments like a browser's window or Node.js's global object.

Infinity

Represents a numeric value greater than any other number. It's the result of operations that overflow or are mathematically defined as infinite.

console.log(1 / 0); // Infinity
console.log(Number.MAX_VALUE * 2); // Infinity

The number line extends forever. The `1 / 0` operation pushes the value far past the maximum representable number, into the infinite realm.

0 Infinity

NaN

Stands for "Not-a-Number." It indicates an invalid or unrepresentable numerical result, such as trying to multiply a string by a number.

console.log("hello" * 5); // NaN
console.log(0 / 0); // NaN

Trying to perform a mathematical operation on a non-numeric value creates a result that isn't a number.

"hello" * 5 = NaN

undefined

Represents a variable that has been declared but has not yet been assigned a value. It's a type and a value in JavaScript.

let myVariable;
console.log(myVariable); // undefined

function doSomething() {
  // no return statement
}
console.log(doSomething()); // undefined

A variable is like a container. When it's declared but empty, its state is undefined.

undefined